package com.haiyi.software.app;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.gson.JsonObject;
import com.haiyi.software.app.basic.ActivityBasicExchanger;

public class ActivityExchanger extends ActivityBasicExchanger {

	private String pid;

	private EditText Editx_linkMan;

	private EditText Editx_linkManCall;

	private EditText Editx_linkManAddress;

	private Button btn_exchange;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_exchange);
		super.onCreate(savedInstanceState);
		initData();
		initComp();

	}

	private void initComp() {
		Editx_linkMan = (EditText) this.findViewById(R.id.Editx_linkMan);
		Editx_linkManCall = (EditText) this
				.findViewById(R.id.Editx_linkManCall);
		Editx_linkManAddress = (EditText) this
				.findViewById(R.id.Editx_linkManAddress);
		btn_exchange = (Button) this.findViewById(R.id.btn_exchange);
		btn_exchange.setOnClickListener(click);
	}

	private void initData() {
		// 商品ID
		pid = this.getIntent().getStringExtra("pid");
	}

	private OnClickListener click = new OnClickListener() {

		@Override
		public void onClick(View v) {

			if (Editx_linkMan.getText().toString().trim().length() == 0
					|| Editx_linkManAddress.getText().toString().trim()
							.length() == 0
					|| Editx_linkManCall.getText().toString().trim().length() == 0) {

				Toast.makeText(getApplicationContext(), "请正确填写信息，否则商品可能会收不到哟！",
						Toast.LENGTH_LONG).show();
				return;
			}

			Map<String, String> info = new HashMap<String, String>();

			info.put("pid", pid);

			info.put("addr", Editx_linkManAddress.getText().toString().trim());

			info.put("linkman", Editx_linkMan.getText().toString().trim());

			info.put("phone", Editx_linkManCall.getText().toString().trim());

			requestNetworkData(info);
		}
	};

	@Override
	public void requestFinish(JsonObject jsonObjectReturn) {

		Toast.makeText(getApplicationContext(),
				jsonObjectReturn.get("desc").getAsString(), Toast.LENGTH_LONG)
				.show();

	}

	@Override
	protected void requestError() {
		// TODO 自动生成的方法存根

	}

}
